Add a failing test

There needs more than 2 * events_to_show events to check if selection
before limiting actually works.

Akinori MUSHA 7 years ago
parent
commit
654da6a4e6
1 changed files with 41 additions and 1 deletions
  1. 41 1
      spec/models/agents/data_output_agent_spec.rb

+ 41 - 1
spec/models/agents/data_output_agent_spec.rb

@@ -242,13 +242,53 @@ describe Agents::DataOutputAgent do
242 242
         })
243 243
       end
244 244
 
245
+      context 'with more events' do
246
+        let!(:event4) do
247
+          agents(:bob_website_agent).create_event payload: {
248
+            'site_title' => 'XKCD',
249
+            'url' => 'http://imgs.xkcd.com/comics/comic1.png',
250
+            'title' => 'Comic 1',
251
+            'date' => '',
252
+            'hovertext' => 'Hovertext for Comic 1'
253
+          }
254
+        end
255
+
256
+        let!(:event5) do
257
+          agents(:bob_website_agent).create_event payload: {
258
+            'site_title' => 'XKCD',
259
+            'url' => 'http://imgs.xkcd.com/comics/comic2.png',
260
+            'title' => 'Comic 2',
261
+            'date' => '',
262
+            'hovertext' => 'Hovertext for Comic 2'
263
+          }
264
+        end
265
+
266
+        let!(:event6) do
267
+          agents(:bob_website_agent).create_event payload: {
268
+            'site_title' => 'XKCD',
269
+            'url' => 'http://imgs.xkcd.com/comics/comic3.png',
270
+            'title' => 'Comic 3',
271
+            'date' => '',
272
+            'hovertext' => 'Hovertext for Comic 3'
273
+          }
274
+        end
275
+
276
+        describe 'limiting' do
277
+          it 'can select the last `events_to_show` events' do
278
+            agent.options['events_to_show'] = 2
279
+            content, _status, _content_type = agent.receive_web_request({ 'secret' => 'secret2' }, 'get', 'application/json')
280
+            expect(content['items'].map {|i| i["title"] }).to eq(["Comic 3", "Comic 2"])
281
+          end
282
+        end
283
+      end
284
+
245 285
       describe 'ordering' do
246 286
         before do
247 287
           agent.options['events_order'] = ['{{hovertext}}']
248 288
           agent.options['events_list_order'] = ['{{title}}']
249 289
         end
250 290
 
251
-        it 'can reorder the events_to_show last events based on a Liquid expression' do
291
+        it 'can reorder the last `events_to_show` events based on a Liquid expression' do
252 292
           agent.options['events_to_show'] = 2
253 293
           asc_content, _status, _content_type = agent.receive_web_request({ 'secret' => 'secret2' }, 'get', 'application/json')
254 294
           expect(asc_content['items'].map {|i| i["title"] }).to eq(["Evolving", "Evolving again"])